// koa body 配置详情: https://github.com/dlau/koa-body
const koa  = require('koa'),
      body = require('koa-body');

const app = koa();

app.use(body());

app.use(function *() {
    console.log(this.request.body); // { firstName: 'Nikhil',favColor: 'blue',password: 'easytoguess' }
    this.body = {name: 'koa-body'};
});

/**
 *
 fetch("http://localhost:3000/", {
  method: "POST",
  headers: {
    "Content-Type": "application/x-www-form-urlencoded"
  },
  body: "firstName=Nikhil&favColor=blue&password=easytoguess"
}).then(function(res) {
  return res.json();
}).then(function(data) {
  console.log(data);
}).catch(function(err) {
  console.log(err)
});
 */

app.listen(3000);